public override GSCore ExecuteMessage(string token, GSCoreCollection args) { if (token.Equals("addCard")) { string tag = args.getSafe(0).getStringValue(); string img1 = args.getSafe(1).getStringValue(); MNReferencedImage i1 = Document.FindImage(img1); if (i1 != null) { SMMemoryGameCard card = new SMMemoryGameCard(Document); card.Tag = tag; card.Image.Image = i1; cards.Add(card); } } else if (token.Equals("mixCards")) { MixCards(); } else if (token.Equals("clearChanged")) { ClearChanged(args); } else if (token.Equals("restart")) { ResetStatus(); } return(base.ExecuteMessage(token, args)); }
public void AddCard(string tg, MNReferencedImage mri) { SMMemoryGameCard nc = new SMMemoryGameCard(Document); nc.Tag = tg; nc.Image.Image = mri; cards.Add(nc); if (matrix != null) { for (int r = 0; r < matrix.GetLength(0); r++) { for (int c = 0; c < matrix.GetLength(1); c++) { if (matrix[r, c] == null) { matrix[r, c] = nc; // to stop loop r = matrix.GetLength(0); break; } } } } }
private SMMemoryGameCard GetRandomCard(Random r, List <SMMemoryGameCard> list) { if (list.Count == 0) { return(null); } int a = r.Next(0, list.Count); SMMemoryGameCard card = list[a]; list.RemoveAt(a); return(card); }
public override bool Load(RSFileReader br) { if (base.Load(br)) { byte b; cards.Clear(); while ((b = br.ReadByte()) != 0) { switch (b) { case 10: Rows = br.ReadInt32(); break; case 11: Columns = br.ReadInt32(); break; case 12: SMMemoryGameCard card = new SMMemoryGameCard(Document); while ((b = br.ReadByte()) != 0) { switch (b) { case 100: card.Tag = br.ReadString(); break; case 110: card.Image.ImageId = br.ReadInt64(); break; } } cards.Add(card); break; case 13: BackImage.ImageId = br.ReadInt64(); break; } } MixCards(); } return(true); }
public override void LoadStatus(RSFileReader br) { base.LoadStatusCore(br); byte b; int r, c; while ((b = br.ReadByte()) != 0) { if (b == 10) { r = br.ReadInt32(); c = br.ReadInt32(); matrix = new SMMemoryGameCard[r, c]; } else if (b == 20) { r = br.ReadInt32(); c = br.ReadInt32(); matrix[r, c] = new SMMemoryGameCard(Document); matrix[r, c].Tag = br.ReadString(); matrix[r, c].State = (SMMemoryCardState)br.ReadInt32(); matrix[r, c].CanChangeState = br.ReadBool(); } } for (r = 0; r < Rows; r++) { for (c = 0; c < Columns; c++) { if (matrix[r, c] != null) { SMMemoryGameCard card = FindCard(matrix[r, c].Tag); if (card != null) { matrix[r, c].Image = card.Image; } } } } }
public override void Paint(MNPageContext context) { base.Paint(context); Rectangle bounds = Area.GetBounds(context); Size cell = new Size(bounds.Width / Columns, bounds.Height / Rows); lastCellSize = cell; if (context.drawSelectionMarks) { for (int r = 0; r < Rows; r++) { for (int c = 0; c < Columns; c++) { Rectangle rect = GetCellRect(context, r, c, cell); rect.Offset(bounds.Location); context.g.DrawRectangle(Pens.LightGray, rect); } } } for (int r = 0; r < Rows; r++) { for (int c = 0; c < Columns; c++) { Rectangle rect = GetCellRect(context, r, c, cell); rect.Offset(bounds.Location); SMMemoryGameCard card = matrix[r, c]; if (card != null) { if (card.State == SMMemoryCardState.Hidden) { if (BackImage.Image != null) { DrawCard(context, rect, BackImage.Image); } } else if (card.State == SMMemoryCardState.HiddenToVisible) { if (BackImage.Image != null) { DrawCard(context, rect, BackImage.Image); } if (card.Image != null) { DrawCard(context, rect, card.Image.Image); } } else if (card.State == SMMemoryCardState.Visible) { if (card.Image != null) { DrawCard(context, rect, card.Image.Image); } } else if (card.State == SMMemoryCardState.VisibleToHidden) { if (card.Image != null) { DrawCard(context, rect, card.Image.Image); } if (BackImage.Image != null) { DrawCard(context, rect, BackImage.Image); } } } } } }