Skip to content
This repository
Newer
Older
100644 80 lines (68 sloc) 2.437 kb
970cd2e8 »
2010-12-07 Commit Snake sample.
1 /*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 using System;
18 using Android.App;
19 using Android.OS;
20 using Android.Widget;
21
22 namespace Mono.Samples.Snake
23 {
24 /**
25 * Snake: a simple game that everyone can enjoy.
26 *
27 * This is an implementation of the classic Game "Snake", in which you control a
28 * serpent roaming around the garden looking for apples. Be careful, though,
29 * because when you catch one, not only will you become longer, but you'll move
30 * faster. Running into yourself or the walls will end the game.
31 *
32 */
b2f3f6f8 »
2012-05-01 [Bug 4804] Snake only supports portrait orientation.
33 [Activity (Label = "Snake", MainLauncher = true, ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait)]
970cd2e8 »
2010-12-07 Commit Snake sample.
34 public class SnakeActivity : Activity
35 {
36 private SnakeView snake_view;
37
38 private static String ICICLE_KEY = "snake-view";
39
40 // Called when Activity is first created. Turns off the title bar, sets up
41 // the content views, and fires up the SnakeView.
42 protected override void OnCreate (Bundle savedInstanceState)
43 {
44 base.OnCreate (savedInstanceState);
45
f330a743 »
2011-01-21 Fixed changes to Resource APIs from P11
46 SetContentView (Resource.Layout.snake_layout);
970cd2e8 »
2010-12-07 Commit Snake sample.
47
f330a743 »
2011-01-21 Fixed changes to Resource APIs from P11
48 snake_view = FindViewById<SnakeView> (Resource.Id.snake);
49 snake_view.SetTextView (FindViewById<TextView> (Resource.Id.text));
970cd2e8 »
2010-12-07 Commit Snake sample.
50
51 if (savedInstanceState == null) {
52 // We were just launched -- set up a new game
53 snake_view.SetMode (GameMode.Ready);
54 } else {
55 // We are being restored
56 Bundle map = savedInstanceState.GetBundle (ICICLE_KEY);
57
58 if (map != null)
59 snake_view.RestoreState (map);
60 else
61 snake_view.SetMode (GameMode.Paused);
62 }
63 }
64
65 protected override void OnPause ()
66 {
67 base.OnPause ();
68
69 // Pause the game along with the activity
70 snake_view.SetMode (GameMode.Paused);
71 }
72
73 protected override void OnSaveInstanceState (Bundle outState)
74 {
75 //Store the game state
76 outState.PutBundle (ICICLE_KEY, snake_view.SaveState ());
77 }
78 }
79 }
Something went wrong with that request. Please try again.